package com.f1ashback.bus.controller;

import com.f1ashback.bus.Qo.FeedbackQo;
import com.f1ashback.bus.Vo.FeedBackVo;
import com.f1ashback.bus.common.AjaxResult;
import com.f1ashback.bus.entity.FeedBack;
import com.f1ashback.bus.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/feedback")
public class FeedBackController {

    @Autowired
    private FeedBackService feedBackService;

    @PutMapping("/appadd")
    public AjaxResult appadd(@RequestBody FeedBack feedBack){
        boolean b = feedBackService.appadd(feedBack);
        if (!b){
            return AjaxResult.error("反馈失败");
        }
        return AjaxResult.success("反馈成功");
    }

    @GetMapping("/list")
    public AjaxResult list(){
        Map<String,List<FeedBackVo>> res = new HashMap<>();
        List<FeedBackVo> list = feedBackService.listAll();
        res.put("list",list);
        return AjaxResult.success(res);
    }

    @GetMapping("/getUserFeedback")
    public AjaxResult getFeedBackAndUser(Long userId){
        if (userId == null){
            return AjaxResult.error("未传值");
        }
        Map<String,List<String>> res = feedBackService.getFeedBackAndUser(userId);
        return AjaxResult.success(res);
    }

    @DeleteMapping("/del/{feedId}")
    public AjaxResult deleteF(@PathVariable Long feedId){
        Integer i = feedBackService.deleteF(feedId);
        if (i <= 0){
            return AjaxResult.error("删除失败");
        }
        return AjaxResult.success("删除成功");
    }

    @PostMapping("/queryFeedback")
    public AjaxResult queryFeedback(@RequestBody FeedbackQo feedbackQo){
        return feedBackService.queryFeedback(feedbackQo);
    }

}
